package logic

import (
	"context"
	"fmt"
	"vipshop/models/mysql"

	"vipshop/vipshoprpc/internal/svc"
	"vipshop/vipshoprpc/vipshoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowLogic {
	return &ShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 完善
func (l *ShowLogic) Show(in *vipshoprpc.ShowRequest) (*vipshoprpc.ShowResponse, error) {
	// todo: add your logic here and delete this line
	var users mysql.User
	mysql.DB.Debug().Where("id=?", in.Id).Find(&users)
	if users.ID == 0 {
		return nil, fmt.Errorf("当前用户不存在 请联系管理员")
	}
	users.Age = in.Age
	users.Origin = in.Origin
	users.HeadImage = in.HeadImage
	mysql.DB.Debug().Where("id=?", in.Id).Updates(&users)
	return &vipshoprpc.ShowResponse{
		Id: int64(users.ID),
	}, nil
}
